package com.ruoyi.system.ali;

import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONObject;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.request.AlipayFundTransToaccountTransferRequest;
import com.alipay.api.response.AlipayFundTransToaccountTransferResponse;
import com.ruoyi.system.domain.OrderPay;
import com.ruoyi.system.domain.ZfbConfig;

/**
 * 支付宝打款
 */
public class TransToaccountService {

    public static void test(OrderPay orderPay) {
        ZfbConfig zfbConfig = new ZfbConfig();

        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", zfbConfig.getAppId(), zfbConfig.getPrivateKey(), "json", "GBK", zfbConfig.getAlipayPublicKey(), "RSA2");
        AlipayFundTransToaccountTransferRequest request = new AlipayFundTransToaccountTransferRequest();
        JSONObject json = new JSONObject();
        json.put("out_biz_no", orderPay.getOrderNo());
        json.put("payee_type", "ALIPAY_LOGONID");
        json.put("payee_real_name", orderPay.getName());
        json.put("payee_account", orderPay.getAccountNumber());
        json.put("amount", orderPay.getAmount());
        json.put("payer_show_name", "码商支付");
        json.put("remark", "代付转账");
        request.setBizContent(json.toJSONString());
        try {
            AlipayFundTransToaccountTransferResponse response = alipayClient.execute(request);
            System.out.println(JSONUtil.toJsonStr(response));
        } catch (Exception e) {

        }
    }
}
